//
//  StoreCategoryListCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/6.
//  Copyright © 2020 王洋. All rights reserved.
//
#import "ZZStarView.h"

#import "StoreCategoryListCell.h"


@interface StoreCategoryListCell ()

@property (nonatomic, strong) ZZStarView *starView;


@end

@implementation StoreCategoryListCell

+ (CGFloat)calculateHeightWithModel:(CommonSellerModule *)model {
    CGFloat top = 1;
    CGFloat storeHeight = 85;
    CGFloat zixunHeight = 22;
    if (model.consultingStar.length == 0) {
        zixunHeight = CGFLOAT_MIN;
    }
    
    CGFloat daodianHeight = 22;
    if (model.arrivalGift.length == 0) {
        daodianHeight = CGFLOAT_MIN;
    }
    
    CGFloat bottom = 15;

    return top + storeHeight + zixunHeight + daodianHeight + bottom;
}

- (void)awakeFromNib {
    [super awakeFromNib];

    [self.starBGView addSubview:self.starView];

    [self.starView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];

    [self.collectControl addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
       
        if (self.StoreCategoryListCellBlock) {
            self.StoreCategoryListCellBlock();
        }
        
    }];

}

- (void)fillCellWithModel:(CommonSellerModule *)model {
    
    NSString *url = [TT_OSSManager reSourceUrl:model.logoUrl type:BA_resizeType_plus];
    [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:url]  placeholderImage:[UIImage imageNamed:@"placeholder"]];
    
    self.storeName.text = model.sellerName;
    
    if (model.distance > 0) {
        if (model.distance < 1000) {
            self.addressLab.text = [NSString stringWithFormat:@"%.fm | %@",model.distance,model.sellerAddress]; ;
        } else {
            self.addressLab.text = [NSString stringWithFormat:@"%.fkm | %@",model.distance/1000,model.sellerAddress]; ;
        }
    } else {
        self.addressLab.text = model.sellerAddress;
    }
    
    self.starView.grade = model.sellerEvaluateStar;

    if (model.sellerEvaluateStar > 0) {
        self.starLab.text = [NSString stringWithFormat:@"%.1f",model.sellerEvaluateStar];
    } else {
        self.starLab.text = @"暂无评分";
    }
        
//    if (model.admId == 13) {
    if (model.examStatus == 2) {
        self.WYXIcon.hidden = NO;
        self.WYXWidth.constant = 40.0f;
    } else {
        self.WYXIcon.hidden = YES;
        self.WYXWidth.constant = CGFLOAT_MIN;
    }
    
    
    self.arriveGiftLab.text = model.arrivalGift;
    self.imGiftLab.text = model.consultingStar;
    
    if (model.consultingStar.length == 0) {
        self.zixunHeight.constant = CGFLOAT_MIN;
    } else {
        self.zixunHeight.constant = 22;
    }
    
    if (model.arrivalGift.length == 0) {
        self.daodianHeight.constant = CGFLOAT_MIN;
    } else {
        self.daodianHeight.constant = 22;
    }
    
    self.favoriteLab.text = [NSString stringWithFormat:@"%ld",(long)model.collectionCount];
    
    self.storeTagImageView.hidden = YES;
    if (model.sellerQualityAuthentication.applyType == 1) {
        self.storeTagImageView.hidden = NO;
        [self.storeTagImageView setImage:[UIImage imageNamed:@"pingpairenzheng"]];
    } else if (model.sellerQualityAuthentication.applyType == 2) {
        self.storeTagImageView.hidden = NO;
        [self.storeTagImageView setImage:[UIImage imageNamed:@"pingzhirenzheng"]];
    } else {
        self.storeTagImageView.hidden = YES;
    }
    
    self.starView.hidden = YES;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.starLab.left = self.storeName.left;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.mainImageView pp_clipCorners:UIRectCornerAllCorners radius:6];
        self.starLab.left = self.storeName.left;
    });
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (ZZStarView *)starView {
    
    if (!_starView) {

        _starView = [[ZZStarView alloc] initWithImage:[UIImage imageNamed:@"daxing_nor"] selectImage:[UIImage imageNamed:@"daxing_sel"] starWidth:12 starHeight:12 starMargin:2 starCount:5 callBack:^(CGFloat userGrade, CGFloat finalGrade) {
        }];
        //默认值, 可以不写, 用户可选分值范围是0.5的倍数.(建议在设置分值之前确定此值)
        _starView.sublevel = 0.5;
        //设置分值, 可以不写, 默认显示0分.(self.params是UIViewController在ZZRouter中扩展的属性, 包含了所有参数)
        _starView.grade = 0.0;
        //最小值, 默认0.5可以不写, 用户可以设置的最低分值.
        _starView.miniGrade = 0;
        _starView.frame = CGRectMake(0, 0, 70, 14);

    }
    return _starView;
}

@end
